home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / ERRMSG.FRM < prev    next >
Text File  |  1997-06-14  |  3KB  |  93 lines

  1. VERSION 5.00
  2. Begin VB.Form FErrorMessage 
  3.    Caption         =   "Look Up Error Messages"
  4.    ClientHeight    =   2700
  5.    ClientLeft      =   1260
  6.    ClientTop       =   2265
  7.    ClientWidth     =   4470
  8.    Icon            =   "ERRMSG.frx":0000
  9.    LinkTopic       =   "FErrorMsg"
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   2700
  12.    ScaleWidth      =   4470
  13.    Begin VB.TextBox txtMessage 
  14.       Appearance      =   0  'Flat
  15.       BackColor       =   &H00C0C0C0&
  16.       BorderStyle     =   0  'None
  17.       Height          =   1215
  18.       Left            =   216
  19.       MultiLine       =   -1  'True
  20.       TabIndex        =   2
  21.       Top             =   1080
  22.       Width           =   4092
  23.    End
  24.    Begin VB.TextBox txtError 
  25.       Height          =   495
  26.       Left            =   228
  27.       TabIndex        =   1
  28.       Text            =   "0"
  29.       Top             =   384
  30.       Width           =   1215
  31.    End
  32.    Begin VB.CommandButton cmdLookup 
  33.       Caption         =   "&Lookup"
  34.       Default         =   -1  'True
  35.       Height          =   495
  36.       Left            =   1656
  37.       TabIndex        =   0
  38.       Top             =   384
  39.       Width           =   1215
  40.    End
  41.    Begin VB.Label lbl 
  42.       Caption         =   "Enter error number (decimal or hexadecimal):"
  43.       Height          =   216
  44.       Left            =   216
  45.       TabIndex        =   3
  46.       Top             =   48
  47.       Width           =   3360
  48.    End
  49. End
  50. Attribute VB_Name = "FErrorMessage"
  51. Attribute VB_GlobalNameSpace = False
  52. Attribute VB_Creatable = False
  53. Attribute VB_PredeclaredId = True
  54. Attribute VB_Exposed = False
  55. Option Explicit
  56.  
  57. Private Sub cmdLookup_Click()
  58.     Dim iMsgId As Long, ret As Long, sVal As String
  59.     sVal = txtError
  60.     ' Recognize leading & as a hex specifier without following H
  61.     If Left$(sVal, 1) = "&" And UCase$(Mid$(sVal, 2, 1)) <> "H" Then
  62.         sVal = "&H" & Mid$(sVal, 2)
  63.     End If
  64.     iMsgId = Val(sVal)
  65.     ' Create the error message
  66.     Dim sNum As String, sMsg As String
  67.     sMsg = String$(256, 0)
  68.     ret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or _
  69.                         FORMAT_MESSAGE_IGNORE_INSERTS, _
  70.                         0&, iMsgId, 0&, sMsg, Len(sMsg), ByVal pNull)
  71.     ' Display it
  72.     sNum = "Error : " & iMsgId & " (&H" & Hex(iMsgId) & ")" & vbCrLf
  73.     If ret Then
  74.         txtMessage = sNum & vbCrLf & Left$(sMsg, lstrlen(sMsg))
  75.     Else
  76.         txtMessage = sNum & vbCrLf & "No such error"
  77.     End If
  78.     cmdLookup.SetFocus
  79.     txtError.SetFocus
  80. End Sub
  81.  
  82.  
  83. Private Sub Form_Activate()
  84.     txtError.SetFocus
  85. End Sub
  86.  
  87.  
  88. Private Sub txtError_GotFocus()
  89.     Debug.Print "Got Focus"
  90.     txtError.SelStart = 0
  91.     txtError.SelLength = 255
  92. End Sub
  93.